﻿// -----------------------------------------------------------------------
// <copyright file="Train_Features_Manager.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace FacePassword.Business_Layer
{
    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using FacePassword.Utilities;

    /// <summary>
    /// TODO: mainpulate anything about Train_Feature table.
    /// </summary>
    public class Train_Features_Manager
    {
        public void AddFeatureVectorToDB(double[] featureVector, int UID)
        {
            try
            {
                string SfeatureVector = null;

                for (int i = 0; i < featureVector.Length - 1; i++)
                {
                    if (i == featureVector.Length - 2)
                    {
                        SfeatureVector += featureVector[i];
                    }
                    else

                        SfeatureVector += featureVector[i] + " ";
                }

                SqlConnection con = new SqlConnection("Data Source=AMIRAASAYED-PC\\SQLEXPRESS;Initial Catalog='Face Password';Integrated Security=True");

                con.Open();

                string FeatureString = "insert into Train_Features(UID_ , FeatureVector) values (@UID , @SfeatureVector)";

                SqlCommand com = new SqlCommand(FeatureString, con);

                SqlParameter ID = new SqlParameter("@UID", UID);

                com.Parameters.Add(ID);

                SqlParameter Vector = new SqlParameter("@SfeatureVector", SfeatureVector);

                com.Parameters.Add(Vector);

                com.ExecuteNonQuery();

                con.Close();
            }
            catch (Exception e)
            {
                throw (e);
               
                Logger.LogException(e);

            }
        }
    }
}
